import axios from "axios"
import { ElMessage } from 'element-plus'
// import common from "../common"
// axios.defaults.withCredentials = true
export default {
    post(url: string, query: any) {
        return new Promise((resolve, reject) => {
            axios.post(`/api${url}`, query, {
                headers: {
                    "clientId": 'when_i_was_young_i_listen_to_the_radio',
                    "clientSecret": 'waiting_for_my_favorite_song',
                    'Content-Type': 'application/json'
                }
            }).then((response: any) => {
                if (response.status == 200 && response.data.code == 0) {
                    ElMessage.error(response.data.msg);
                    reject(response.data.msg);
                    return
                }
                if (response.status == 200 && response.data.code == 1) {
                    return resolve(response.data)
                } else if (response.status == '404') {
                    ElMessage.error("接口不存在");
                    reject(response.data.msg);
                } else if (response.status == '500') {
                    ElMessage.error("服务器内部错误");
                    reject(response.data.msg);
                } else if (response.status == '403') {
                    ElMessage.error("服务器拒绝访问");
                    reject(response.data.msg);
                } else {
                    ElMessage.error(response.data.msg || "远程服务器异常，请稍后重试。");
                    reject(response.data.msg);
                }
            }).catch((err) => {
                ElMessage.error("远程服务器异常，请稍后重试。");
                reject(err);
            })
        })

    },

}